home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Baseline Alignment.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  2.3 KB  |  91 lines  |  [TEXT/KAHL]

  1. /****************************************************************************************************
  2.     6/96 bob    Updated #includes to support changed GX Library names.
  3.     
  4.     ©1990 - 1996  Apple Computer, Inc.
  5.     All rights reserved.
  6. ****************************************************************************************************/
  7. #include <Types.h>
  8. #include <QuickDraw.h>
  9. #include <Fonts.h>
  10. #include <Windows.h>
  11. #include <Menus.h>
  12. #include <SegLoad.h>
  13. #include <Memory.h>
  14. #include <Desk.h>
  15.  
  16. #include <GXGraphics.h>
  17. #include "GraphicsLibraries.h"
  18. #include <GXEnvironment.h>
  19.  
  20. #include <GXTypes.h>
  21. #include <GXLayout.h>
  22. #include "LayoutLibrary.h"
  23.  
  24. #include "SampleInterface.h"
  25.  
  26.  
  27. short MyStrLen(char *x);
  28. static short MyStrLen(x)
  29. char    *x;
  30.     {
  31.     short c = 0;
  32.     while (*x++) c++;
  33.     return c;
  34.     }    /* MyStrLen */
  35.  
  36. void BaselineAlignment(WindowPtr sampleWindow)
  37.     {
  38.     /* Variables */
  39.     char                *myString = "Drop Caps";
  40.     gxLayoutOptions        gxLayoutOptions;
  41.     gxLineBaselineRecord    gxLineBaselineRecord;
  42.     gxPoint                myPoint;
  43.     gxRunControls            gxRunControls;
  44.     gxShape                layout;
  45.     short                len, level = 0, runLengths[4];
  46.     gxStyle                dropCapsStyle, regularStyle, styleArray[4];
  47.     gxViewPort            aViewPort;
  48.     
  49.     /* Initialization */
  50.     
  51.     myPoint.x = ff(20);
  52.     myPoint.y = ff(50);
  53.     
  54.     aViewPort = GXNewWindowViewPort(sampleWindow);
  55.     SetDefaultViewPort(aViewPort);
  56.     
  57.     len = MyStrLen(myString);
  58.     runLengths[0] = runLengths[2] = 1;
  59.     runLengths[1] = 4;
  60.     runLengths[3] = 3;
  61.     
  62.     regularStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(40), 0, nil, nil, 0, nil);
  63.     
  64.     InitializeRunControls(&gxRunControls);
  65.     gxRunControls.baselineType = gxHangingBaseline;
  66.     dropCapsStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(70), 0, &gxRunControls, nil, 0, nil);
  67.     
  68.     InitializeLayoutOptions(&gxLayoutOptions);
  69.     GXGetStyleBaselineDeltas(regularStyle, gxRomanBaseline, gxLineBaselineRecord.deltas);
  70.     gxLayoutOptions.baselineRec = &gxLineBaselineRecord;
  71.     
  72.     styleArray[0] = styleArray[2] = dropCapsStyle;
  73.     styleArray[1] = styleArray[3] = regularStyle;
  74.     
  75.     layout = GXNewLayout(
  76.         1, &len, (void *) &myString,
  77.         4, runLengths, styleArray,
  78.         1, &len, &level,
  79.         &gxLayoutOptions, &myPoint);
  80.     GXDrawShape(layout);
  81.     
  82.     GXSetStyleTextSize(dropCapsStyle, ff(110));
  83.     GXMoveShape(layout, 0, ff(100));
  84.     GXDrawShape(layout);
  85.     
  86.     GXDisposeShape(layout);
  87.     GXDisposeStyle(regularStyle);
  88.     GXDisposeStyle(dropCapsStyle);
  89.     GXDisposeViewPort(aViewPort);
  90.     }    /* main */
  91.